package com.sfy.login.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Description 日期格式化工具类
 * @Author 谷晓天
 * @Date 2021/7/3 2:56 下午
 */
public class TimeUtil {
     public static String TimeFormat(Date time) {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         return simpleDateFormat.format(time);
     }

    /**
      * 获取N天后
      */
    public static Date getDate(Integer days){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DAY_OF_MONTH,days);
        return calendar.getTime();
    }

    /**
     * 计算年龄
     */
    public static int diffYear(Date birthday) {
        Calendar calendar = Calendar.getInstance();
        Calendar calendar1 = Calendar.getInstance();
        calendar1.setTime(birthday);
        return calendar.get(Calendar.YEAR) - calendar1.get(Calendar.YEAR);
    }
}
